package com.aspose.cells;

class zawi extends zawe {
   private zagu[][] g;
   private int h;
   private int i;
   private int[] j;
   private int k;
   private boolean l;
   private int m;
   private int n;
   private int o;
   private int p;
   private int q;
   private int r;
   private boolean s;
   private boolean t;
   private int u;
   private int v;
   private zagu[] w;
   private zagu x;
   private int y;
   private int z;
   private int A;

   public zawi(zagu[][] var1) {
      this(var1, 0, 0, (int[])null, var1.length, var1[0].length, 6, zzk.a, 0, 0, false, false, var1[0].length);
   }

   public zawi(zagu[][] var1, int var2, int var3, int[] var4, int var5, int var6, int var7, zagu var8, int var9, int var10, boolean var11, boolean var12, int var13) {
      super(var7, var8, var9, var10, var11, var12);
      this.g = var1;
      this.h = var5;
      this.i = var6;
      this.j = var4;
      this.k = var13;
      this.l = var5 < 2 && var6 < 2;
      this.m = var2;
      this.n = var3;
      this.H();
   }

   zawi(zawi var1) {
      super(var1.b, var1.a, var1.e, var1.f, var1.c, var1.d);
      this.g = var1.g;
      this.h = var1.h;
      this.i = var1.i;
      this.j = var1.j;
      this.k = var1.k;
      this.l = var1.l;
      this.m = var1.m;
      this.n = var1.n;
      this.o = var1.o;
      this.p = var1.p;
      this.q = var1.q;
      this.r = var1.r;
      this.s = var1.s;
      this.t = var1.t;
      this.u = var1.u;
      this.v = var1.v;
      this.w = var1.w;
      this.x = var1.x;
      this.y = var1.y;
      this.z = var1.z;
      this.A = var1.A;
   }

   public zahn b(zaay var1) {
      return new zawi(this);
   }

   public int c() {
      return this.h;
   }

   public int d() {
      return this.i;
   }

   public int e() {
      return this.l ? 1 : (this.h < 2 ? this.i : (this.i < 2 ? this.h : this.h * this.i));
   }

   public boolean l() {
      return this.l;
   }

   public boolean m() {
      return this.l || this.h < 2;
   }

   public boolean n() {
      return this.l || this.i < 2;
   }

   public zagu a(int var1, int var2) {
      if (this.l) {
         return this.x;
      } else if (this.t) {
         return this.a;
      } else {
         var1 += this.m;
         if (var1 >= this.o && var1 <= this.p) {
            zagu[] var3 = this.g[var1];
            if (var3 != null) {
               var2 += this.n;
               if (this.j != null && var1 < this.j.length) {
                  var2 -= this.j[var1];
               }

               if (var2 >= 0 && var2 < var3.length) {
                  return var3[var2];
               }
            }

            return this.a;
         } else {
            return this.a;
         }
      }
   }

   public void f() {
      if (!this.l && !this.t) {
         if (this.p == this.o) {
            this.v = this.y - 1;
         } else {
            this.u = this.o - 1;
            if (this.D()) {
               --this.v;
            } else {
               this.s = true;
               this.G();
            }
         }

      }
   }

   public boolean b(int var1, int var2) {
      if (!this.l && !this.t) {
         var1 += this.m;
         if (var1 > this.p) {
            return false;
         } else {
            if (var1 < this.o) {
               var1 = this.o;
               var2 = 0;
            }

            if (this.u != var1) {
               this.u = var1;
               if (!this.C()) {
                  return this.D();
               }
            }

            var2 += this.A;
            if (var2 == this.v && this.v < this.z) {
               return true;
            } else {
               this.v = Math.max(var2, this.y) - 1;
               return this.g();
            }
         }
      } else {
         return false;
      }
   }

   public boolean a(int var1) {
      if (!this.l && !this.t) {
         if (this.h < 2) {
            var1 += this.A;
            if (var1 == this.v && this.v < this.z) {
               return true;
            } else {
               this.v = Math.max(var1, this.y) - 1;
               return this.g();
            }
         } else {
            return this.i < 2 ? this.b(var1, 0) : this.b(var1 % this.i, var1 / this.i);
         }
      } else {
         return false;
      }
   }

   public boolean g() {
      if (!this.l && !this.t) {
         if (this.o == this.p) {
            ++this.v;
            if (this.v < this.z) {
               this.x = this.w[this.v];
               if (!a(this.x, this.a)) {
                  return true;
               }

               return this.E();
            }
         } else if (this.u <= this.p) {
            ++this.v;
            if (this.v < this.z) {
               this.x = this.w[this.v];
               if (!a(this.x, this.a)) {
                  return true;
               }

               if (this.E()) {
                  return true;
               }
            }

            return this.D();
         }

         return false;
      } else {
         return false;
      }
   }

   private boolean C() {
      this.w = this.g[this.u];
      if (this.w == null) {
         return false;
      } else {
         if (this.j != null) {
            if (this.u < this.j.length) {
               this.A = this.n - this.j[this.u];
            } else {
               this.A = this.n;
            }
         }

         if (this.s) {
            this.y = Math.max(0, this.q + this.A);
            if (this.y >= this.w.length) {
               return false;
            }

            this.z = Math.min(this.w.length, this.r + this.A + 1);
            if (this.z <= this.y) {
               return false;
            }

            this.v = this.y;
         } else {
            this.z = Math.min(this.w.length, this.i + this.A);
            if (this.z < 1) {
               return false;
            }

            if (this.A < 0) {
               this.y = 0;
               this.v = 0;
            } else {
               this.y = this.A;
               if (this.y >= this.z) {
                  return false;
               }

               this.v = this.y;
            }
         }

         this.x = this.w[this.v];
         return !a(this.x, this.a) ? true : this.E();
      }
   }

   private boolean D() {
      while(true) {
         ++this.u;
         if (this.u <= this.p) {
            if (!this.C()) {
               continue;
            }

            return true;
         }

         return false;
      }
   }

   private boolean E() {
      while(true) {
         ++this.v;
         if (this.v < this.z) {
            this.x = this.w[this.v];
            if (a(this.x, this.a)) {
               continue;
            }

            return true;
         }

         return false;
      }
   }

   public zagu h() {
      if (this.x.b() == 13) {
         zzh var1 = (zzh)this.x;
         if (var1.k().c() == 2) {
            this.x = var1.k().n();
            this.g[this.u][this.v] = this.x;
         }
      }

      return this.x;
   }

   public int i() {
      return this.l ? 0 : this.u - this.m;
   }

   public int j() {
      return this.l ? 0 : this.v - this.A;
   }

   public int k() {
      if (this.l) {
         return 0;
      } else if (this.h < 2) {
         return this.v - this.A;
      } else {
         return this.i < 2 ? this.u - this.m : (this.u - this.m) * this.i + this.v - this.A;
      }
   }

   public zahn b(int var1) {
      if (this.t) {
         return new zawz(this.a, 1, this.i);
      } else if (this.h < 2) {
         return this;
      } else {
         var1 += this.m;
         if (var1 >= 0 && var1 <= this.g.length && this.g[var1] != null) {
            int var2 = this.n;
            if (this.j != null && var1 < this.j.length) {
               var2 -= this.j[var1];
            }

            zagu[] var3 = this.g[var1];
            return (zahn)(var2 < var3.length && var2 > -this.i ? new zawg(var3, false, var2, this.i, this.b, this.a, this.f, this.d) : new zawz(this.a, this.b, 1, this.i));
         } else {
            return new zawz(this.a, this.b, 1, this.i);
         }
      }
   }

   public zahn c(int var1) {
      if (this.t) {
         return new zawz(this.a, 1, this.i);
      } else {
         var1 += this.n;
         return (zahn)(var1 >= 0 && var1 < this.k ? new zawh(this.g, this.m, var1, this.j, this.h, this.b, this.a, this.e, this.f, this.c, false, this.k) : new zawz(this.a, this.b, this.h, 1));
      }
   }

   public boolean a(zagu var1) {
      return a(var1, this.l ? this.x : this.a);
   }

   public void a(zaay var1) {
      if (this.c && var1.g != this.e) {
         this.m += var1.g - this.e;
         this.e = var1.g;
         if (this.d && var1.h != this.f) {
            this.n += var1.h - this.f;
            this.f = var1.h;
         }

         this.H();
      } else if (this.d && var1.h != this.f) {
         this.n += var1.h - this.f;
         this.f = var1.h;
         this.H();
      }

   }

   public boolean q() {
      return this.s;
   }

   public int r() {
      if (!this.s) {
         this.F();
      }

      return this.t ? -1 : this.o - this.m;
   }

   public int s() {
      if (!this.s) {
         this.F();
      }

      return this.t ? -1 : this.p - this.m;
   }

   public int t() {
      if (!this.s) {
         this.F();
      }

      return this.q;
   }

   public int u() {
      if (!this.s) {
         this.F();
      }

      return this.r;
   }

   private void F() {
      this.s = true;
      if (this.o != this.p) {
         int[] var1 = new int[4];
         if (a(this.g, this.m, this.n, this.j, this.h, this.i, this.a, var1)) {
            this.o = var1[0] + this.m;
            this.q = var1[1];
            this.p = var1[2] + this.m;
            this.r = var1[3];
         } else {
            this.G();
         }

      } else {
         while(true) {
            if (!a(this.w[this.y], this.a)) {
               this.q = this.y - this.A;
               this.r = this.q;
               --this.z;
               if (this.y < this.z) {
                  do {
                     if (!a(this.w[this.z], this.a)) {
                        this.r = this.z - this.A;
                        break;
                     }

                     --this.z;
                  } while(this.z != this.y);
               }

               ++this.z;
               break;
            }

            ++this.q;
            if (this.q > this.r) {
               this.G();
               break;
            }
         }

      }
   }

   static boolean a(zagu[][] var0, int var1, int var2, int[] var3, int var4, int var5, zagu var6, int[] var7) {
      int var8 = -1;
      int var9 = -1;
      int var10 = var2;
      int var14 = Math.min(var0.length, var1 + var4) - 1;

      for(int var15 = Math.max(0, var1); var15 <= var14; ++var15) {
         zagu[] var13 = var0[var15];
         if (var13 != null) {
            if (var3 != null) {
               if (var15 < var3.length) {
                  var10 = var2 - var3[var15];
               } else {
                  var10 = var2;
               }
            }

            int var11 = Math.min(var10 + var5, var13.length) - 1;
            int var12 = Math.max(0, var10);
            if (var12 <= var11) {
               label184:
               do {
                  if (!a(var13[var12], var6)) {
                     var7[0] = var15 - var1;
                     var8 = var12 - var10;
                     var9 = var8;
                     if (var11 > var12) {
                        do {
                           if (!a(var13[var11], var6)) {
                              var9 = var11 - var10;
                              break label184;
                           }

                           --var11;
                        } while(var11 != var12);
                     }
                     break;
                  }

                  ++var12;
               } while(var12 <= var11);
            }

            if (var9 >= 0) {
               if (var14 == var15) {
                  var7[1] = var8;
                  var7[2] = var7[0];
                  var7[3] = var9;
                  return true;
               }

               do {
                  do {
                     var13 = var0[var14];
                  } while(var13 == null);

                  if (var3 != null) {
                     if (var14 < var3.length) {
                        var10 = var2 - var3[var14];
                     } else {
                        var10 = var2;
                     }
                  }

                  var11 = Math.min(var10 + var5, var13.length) - 1;
                  var12 = Math.max(0, var10);
                  if (var12 <= var11) {
                     label197: {
                        while(a(var13[var12], var6)) {
                           ++var12;
                           if (var12 > var11) {
                              break label197;
                           }
                        }

                        var7[2] = var14 - var1;
                        int var16 = var5 - 1;
                        if (var8 == 0 && var9 == var16) {
                           var7[1] = 0;
                           var7[3] = var16;
                           return true;
                        }

                        int var17 = var12 - var10;
                        if (var17 < var8) {
                           if (var17 == 0 && var9 == var16) {
                              var7[1] = 0;
                              var7[3] = var16;
                              return true;
                           }

                           var8 = var17;
                        } else if (var17 > var9) {
                           if (var8 == 0 && var17 == var16) {
                              var7[1] = 0;
                              var7[3] = var16;
                              return true;
                           }

                           var9 = var17;
                        }

                        var12 = Math.max(var12, var9 + var10);
                        if (var11 > var12) {
                           do {
                              if (!a(var13[var11], var6)) {
                                 var9 = var11 - var10;
                                 if (var8 == 0 && var9 == var16) {
                                    var7[1] = 0;
                                    var7[3] = var16;
                                    return true;
                                 }
                                 break;
                              }

                              --var11;
                           } while(var11 != var12);
                        }

                        --var14;
                        if (var15 == var14) {
                           var7[1] = var8;
                           var7[3] = var9;
                           return true;
                        }

                        label150:
                        while(true) {
                           while(true) {
                              var13 = var0[var15];
                              if (var13 != null) {
                                 if (var3 != null) {
                                    if (var15 < var3.length) {
                                       var10 = var2 - var3[var15];
                                    } else {
                                       var10 = var2;
                                    }
                                 }

                                 var11 = Math.min(var10 + var5, var13.length) - 1;
                                 var12 = Math.max(0, var10);
                                 if (var12 <= var11) {
                                    int var18 = var10 + var8;
                                    if (var12 < var18) {
                                       while(a(var13[var12], var6)) {
                                          ;
                                       }

                                       var8 = var12 - var10;
                                       if (var8 == 0 && var9 == var16) {
                                          var7[1] = 0;
                                          var7[3] = var16;
                                          return true;
                                       }

                                       ++var12;
                                       if (var12 == var18) {
                                          break label150;
                                       }
                                    }

                                    var12 = var10 + var9;
                                    if (var11 > var12) {
                                       while(a(var13[var11], var6)) {
                                          ;
                                       }

                                       var9 = var11 - var10;
                                       if (var8 == 0 && var9 == var16) {
                                          var7[1] = 0;
                                          var7[3] = var16;
                                          return true;
                                       }

                                       --var11;
                                       if (var11 == var12) {
                                          break label150;
                                       }
                                    }

                                    if (var8 == 0 && var9 == var16) {
                                       break label150;
                                    }
                                 }

                                 --var14;
                                 if (var15 == var14) {
                                    var7[1] = var8;
                                    var7[3] = var9;
                                    return true;
                                 }
                              }
                           }
                        }
                     }
                  }

                  --var14;
               } while(var14 != var15);

               var7[1] = var8;
               var7[2] = var7[0];
               var7[3] = var9;
               return true;
            }
         }
      }

      return false;
   }

   private void G() {
      this.t = true;
      this.p = -1;
      this.o = -1;
      this.r = -1;
      this.q = -1;
   }

   private void H() {
      this.A = this.n;
      this.u = this.m - 1;
      this.v = this.k;
      this.s = false;
      this.t = false;
      if (this.m < this.g.length && this.n < this.k && this.m > -this.h && this.n > -this.i) {
         if (this.h != 1 && this.m != this.g.length - 1) {
            if (this.m + this.h == 1) {
               this.u = 0;
            }
         } else {
            this.u = this.m;
         }

         if (this.u >= this.m) {
            this.w = this.g[this.u];
            if (this.w == null) {
               this.s = true;
               this.G();
            } else {
               if (this.j != null && this.u < this.j.length) {
                  this.A -= this.j[this.u];
               }

               if (this.A < this.w.length && this.A > -this.i) {
                  if (this.l) {
                     this.s = true;
                     this.G();
                     this.x = this.w[this.A];
                  } else {
                     this.s = false;
                     this.y = Math.max(0, this.A);
                     this.z = Math.min(this.w.length, this.i + this.A);
                     this.q = this.y - this.A;
                     this.r = this.z - this.A - 1;
                     this.o = this.u;
                     this.p = this.o;
                  }
               } else {
                  this.s = true;
                  this.G();
               }
            }
         } else {
            this.s = false;
            this.q = 0;
            this.r = this.i - 1;
            this.o = Math.max(0, this.m);
            this.p = Math.min(this.m + this.h, this.g.length) - 1;
         }
      } else {
         this.s = true;
         this.G();
      }

   }
}
